﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>确认订单</title>
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="yes" name="apple-touch-fullscreen">
    <meta name="format-detection" content="telephone=no">
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" />
    <link href="../css/ydui.css?v=1.1.4" rel="stylesheet" />
    <script src="../js/ydui.flexible.js"></script>
    <link rel="stylesheet" type="text/css" href="../css/all.css?v=20180302"/>
    <style type="text/css">
        .cell-item {
            padding: 0;
        }
    </style>
</head>

<body ms-controller="ordersure" class="ms-controller">
    <div class="g-flexview">
        <div class="g-scrollview">
            <div class="order-sure" >
            	<p class="notavailable" ms-if="@Address.length==0">很抱歉,您暂时没有收货地址</p>
                <div class="adresscontent clearfix" ms-if="@Address.length>0">
                    <p class="iconfont icon-dingwei"></p>
                    <p class="text">
                    	<span>{{@Address[0].City}}{{@Address[0].County}}{{@Address[0].Title}}{{@Address[0].Address}}</span>
                    	<span>{{@Address[0].Receiver}}{{@Address[0].Telephone}}</span>
                    </p>
                    <a class="iconfont icon-gengduo" ms-attr="{href:'../user/address.html?returnurl='+window.location.href}"></a>
                </div>
<!--                <p class="adressperson"><span>{{@Address[0].Receiver}}</span><span>{{@Address[0].Telephone}}</span></p>--> 
				<div class="yujitime" ms-if="@Address.length==0">
                    <div class="content">
                       	<a ms-attr="{href:'../user/addressadd.html?returnurl='+window.location.href}"><p>新增收货地址</p></a>
                    </div>
                 </div>
            </div>
            <div class="order-content">
                <div class="whiteconte">
                    <!--<p class="contenttitle">永辉超市</p>-->
                    <div class="orderlist">
                        <div class="ifylist-list clearfix" ms-for="el in @productlist">
                            <a>
                                <img ms-attr="{'src':ComFunJS.FilePath(el.ImgUrl,'/135/120')}">
                                <div class="list-content">
                                    <p class="title">{{el.Title}}</p>
                                    <p class="price"><span>￥</span>{{el.Price1}}<span ms-if="el.Point>0" style="padding-left:5px;">可用存款:￥{{el.Point}}</span><i class="fr">×{{el.Qty}}</i></p>
                                </div>
                            </a>
                        </div>

                    </div>
                    <p class="addtotal">共{{@AllTotal}}件商品</p>
	                <div class="cell-item margin">
	                    <div class="cell-left">商品备注:</div>
	                    <div class="cell-right"><input type="text" class="cell-input" placeholder="请填写商品备注" autocomplete="off" ms-duplex="@remark"/></div>
	                </div>                       
                    <p class="goodsprice">商品总额:<span>¥{{@AllPrice}}</span></p>
                    <p class="goodsprice">存钱罐支付:<span>¥{{@Point>@AllPoint?@AllPoint:@Point}}</span></p>
                    <!--<p class="goodsprice" style="color:#ff0000;">存钱罐余额:<span>¥{{@Point}}</span></p>-->
                    <p class="pocket" style="color:#ff0000;">
                        实付金额:¥{{@Point>@AllPoint?(@AllPrice-@AllPoint):(@AllPrice-@Point)}}
                    </p>
                </div>
            </div>
        </div>
        <div class="order-submit" >
            <a ms-on-tap="@GoToOrder">提交订单</a>
        </div>
    </div>

    <script src="//cdn.bootcss.com/jquery/2.0.0/jquery.min.js"></script>
    <script src="../js/ydui.js"></script>
    <script src="../js/avalon.mobile.min.js"></script>
    <script src="../js/ComFunJS.js?v=20180331"></script>
    <script>
        var model = avalon.define({
            $id: "ordersure",
            AllTotal: 0,
            AllPrice: 0,
            AllPoint: 0,
            productlist: [],
            Address: [],
            remark: "",//订单备注
            Point: 0,
            ctype: ComFunJS.getQueryString("ctype", "1"),
            getorder: function () {

                $.getJSON("/api/user/address/first", function (r) {
                    model.Address = r.result;
                })

                var plist = cart.getProductList(model.ctype, true);
                if (plist.length > 0) {
                    $.post("/api/pro/cart", { P1: JSON.stringify(plist) }, function (r) {
                        if (r.error == "") {
                            model.productlist = r.result;

                            var qty = cart.getProductQty(model.ctype, true);
                            model.AllTotal = qty.Qty2;
                            model.AllPrice = qty.Price1;
                            model.AllPoint = qty.Point;
                        }

                    })
                }
                $.getJSON("/api/user/userinfo", function (r) {
                    if (r.error == "" && r.result) {
                        model.Point = r.result.Point;
                    }
                })
            },
            GoToOrder: function () {
                var plist = cart.getProductList(model.ctype, true);
                if (plist.length == 0) {
                    YDUI.dialog.toast("请选择商品", "none", 1000);
                    return;
                }
                if (model.Address.length == 0) {
                    YDUI.dialog.toast("请选择收货地址", "none", 1000);
                    return;
                }
                YDUI.dialog.loading.open("正在生成订单...")
                $.post("/api/order/add", { P1: JSON.stringify(plist), "aid": model.Address[0].ID, "remark": model.remark, "ctype": model.ctype }, function (r) {
                    YDUI.dialog.loading.close();
                    if (r.error == "") {
                        YDUI.dialog.toast("提交订单成功,请立即支付...", "none", 2000, function () {
                            window.location.href = "pay.html?id=" + r.result;
                        });
                       
                    } else {
                        YDUI.dialog.toast(r.error, "none", 2000);
                    }

                })
                
            }
        })
        avalon.ready(function () {
           
            if (ComFunJS.isLogin(true)) {
                model.getorder()
            }
           
        })
    </script>

</body>
</html>
